Step 6: Calling BFS from the Main Loop

Finally, we'll fill in the `elif cmd == "bfs":` block. This is very simple: just get the `start_node` and call our new `solve_bfs` function.

Guidance for Step 6

  • Function Call: Call the `solve_bfs` function. The first argument should be the `start_node` variable we just parsed.
  • Newline: To match the required output format, you must print a newline character (`"\n"`) after the BFS traversal is complete.
# ... inside the main for loop ...

    elif cmd == "dfs":
        # ... (from step 4) ...
        pass

    elif cmd == "bfs":
        start_node = int(line[1])

        # BFS handles its own visited set
        solve_bfs(______, adj, U)

        # Print a newline to end this command's output
        print(______, end='')

                
Copied!